﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessOneCanteenDetailsReportDetail
// 文件功能描述：一食堂详细消费统计表数据访问层
//
// 
// 创建标识：2012-05-21 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbAdapter.sqldbAdapter;
using System.Data;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessOneCanteenDetailsReportDetail
    {
        /// <summary>
        /// 获取一食堂消费明细表的数量
        /// </summary>
        /// <returns></returns>
        public int GetOneCanteenDetailsReportDetailCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from CUNSUME_DETAIL_VIEW1_DETAIL";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select Dep_ID,deptName from DeptView order by Dep_ID";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        public int GetOneCanteenDetailsReportDetailCountWhere(string Condition)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from CUNSUME_DETAIL_VIEW1_DETAIL where 1=1 " + Condition;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取一食堂详细消费明细表
        /// </summary>
        /// <returns></returns>
        public DataSet BindList(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY RDATETIME DESC) rownumber,* " +
                               "from CUNSUME_DETAIL_VIEW1_DETAIL where 1=1 " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        public DataSet GetListAll(string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select * from CUNSUME_DETAIL_VIEW1_DETAIL where 1=1 " + strquery + " order by RDATETIME DESC";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }
    }
}
